package playground.fibu.ejb;

import java.util.ArrayList;
import java.util.List;

import playground.fibu.ejb.dao.AccountDAO;
import playground.fibu.ejb.dao.DAOFactory;
import playground.fibu.ejb.dao.FibuDAOException;
import playground.fibu.ejb.entity.Account;

public class AccountBO {

	private Account account;

	public AccountBO() {
		account = new Account();
	}

	public AccountBO(Account acc) {
		account = acc;
	}

	public void save() throws FibuDAOException {
		AccountDAO dao = DAOFactory.getDAOFactory(DAOFactory.MYSQL)
				.getAccountDAO();
		dao.save(account);
	}

	public void delete() throws FibuDAOException {
		AccountDAO dao = DAOFactory.getDAOFactory(DAOFactory.MYSQL)
				.getAccountDAO();
		dao.delete(account);
	}

	public static List<Account> findAll() throws FibuDAOException{
		return DAOFactory.getDAOFactory(DAOFactory.MYSQL)
				.getAccountDAO().findAll();
	}

	public static Account findByPrimaryKey(String key) throws FibuDAOException {
		return DAOFactory.getDAOFactory(DAOFactory.MYSQL).getAccountDAO()
				.findByPrimaryKey(Long.parseLong(key));
	}

	public String getIban() {
		return account.getIban();
	}

	public void setIban(String iban) {
		account.setIban(iban);
	}

	public String getAccountName() {
		return account.getAccountName();
	}

	public void setAccountName(String accountName) {
		account.setAccountName(accountName);
	}

	public long getId() {
		return account.getId();
	}
	
	public Account getAccountEntity(){
		return account;
	}
}
